/****************************************
File: opdracht6.cpp

This file is part of Stellar

This program shows a fictional solar system and
provides several methods of interactions.

Copyright (C) 2001 David Stibbe (dstibbe@gmail.com)
                     and Gerrit Jan Jansen

Stellar is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
****************************************/
#include "opdracht6.h"

planet_data* cPlanet_data(	float rotation1[],
							float translation1[],
							float color1[],
							float rotation_speed1,
							float size1,
							int numberOfMoons1,
							moon* moon_list1[],
							model* shape1 ,
							char* nameInput){

	int i;
	planet_data* data=new planet_data;

	data->rotation_speed=rotation_speed1;
	data->numberOfMoons=numberOfMoons1;
	data->size=size1;
	data->shape=shape1;

	for(i=0;i<3;i++){
		data->rotation[i]=rotation1[i];
		data->translation[i]=translation1[i];
		data->color[i]=color1[i];
	}
	for(i=0;i<numberOfMoons1;i++)
		data->moon_list[i]=moon_list1[i];

	strncpy(data->name,nameInput,16);
	return data;
}


moon_data* cMoon_data(	float rotation1[],
						float translation1[],
						float color1[],
						float rotation_speed1,
						float size1,
						model* shape1 ){

	int i;
	moon_data* data=new moon_data;

	data->rotation_speed=rotation_speed1;
	data->size=size1;
	data->shape=shape1;

	for(i=0;i<3;i++){
		data->rotation[i]=rotation1[i];
		data->translation[i]=translation1[i];
		data->color[i]=color1[i];
	}

	return data;
}



/********************************
 *            PLANET            *
 ********************************/

planet::planet(planet_data* moon){
	data=moon;
	angle=0;
}

void planet:: getTranslation(float * target){
	target[M_X]=data->translation[M_X];
	target[M_Y]=data->translation[M_Y];
	target[M_Z]=data->translation[M_Z];
}

void planet:: getRotation(float *target){
	target[M_X]=data->rotation[M_X];
	target[M_Y]=data->rotation[M_Y];
	target[M_Z]=data->rotation[M_Z];
}

void planet:: rotate(){
	angle+=data->rotation_speed;
}
void planet::rotate(float rotFactor){
	angle+=data->rotation_speed*rotFactor;
}
float planet:: getAngle(){
	return angle;
}

float planet:: getSize(){
	return data->size;
}


void planet:: getColor(float *target){
	target[M_X]=data->color[M_X];
	target[M_Y]=data->color[M_Y];
	target[M_Z]=data->color[M_Z];
}


void planet::reset(){
	angle=0;
}



moon* planet::getMoon(int n){
	return data->moon_list[n];
}

int planet::getMoonN(){
	return data->numberOfMoons;
}


model* planet::getModel(){
	return data->shape;
}


/********************************
 *            MOON              *
 ********************************/


moon::moon(moon_data* moon){
	data=moon;
	angle=0;
}

void moon:: getTranslation(float *target){
	target[M_X]=data->translation[M_X];
	target[M_Y]=data->translation[M_Y];
	target[M_Z]=data->translation[M_Z];
}
void moon:: getRotation(float *target){
	target[M_X]=data->rotation[M_X];
	target[M_Y]=data->rotation[M_Y];
	target[M_Z]=data->rotation[M_Z];
}
void moon:: rotate(){
	angle+=data->rotation_speed;
}
void moon:: rotate(float rotFactor){
	angle+=rotFactor*data->rotation_speed;
}
float moon:: getAngle(){
	return angle;
}

float moon:: getSize(){
	return data->size;
}

void moon:: getColor(float* target){
	target[M_X]=data->color[M_X];
	target[M_Y]=data->color[M_Y];
	target[M_Z]=data->color[M_Z];
}


void moon::reset(){
	angle=0;
}

model* moon::getModel(){
	return data->shape;
}
